package com.cxyzy.demo.tween_anims

import android.os.Bundle
import android.view.View
import android.view.animation.Animation
import android.view.animation.ScaleAnimation
import androidx.appcompat.app.AppCompatActivity
import com.cxyzy.demo.R
import kotlinx.android.synthetic.main.activity_scale_up.*

/**
 * 动画样例：放大控件
 */
class ScaleUpActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_scale_up)
        initView()
    }

    private fun initView() {
        toScaleUpBtn.setOnClickListener { scaleUp(it) }
    }

    private fun scaleUp(srcView: View) {
        val animateTime = 2000L
        val animation = ScaleAnimation(1f, 2f, 1f, 2f,
                Animation.RELATIVE_TO_SELF, 0f, Animation.RELATIVE_TO_SELF, 0f)
        animation.fillAfter = true
        animation.duration = animateTime
        srcView.startAnimation(animation)
    }
}
